<template>
  <div class="social-item">
    <section class="item-head">
      <div class="avatar"><img :src="itemData.headImageUrl || require('@/assets/images/avatar.png')" alt=""></div>
      <div class="info">
        <div class="name">{{itemData.nickName}}</div>
        <div class="time">{{formTime(itemData.topics.createTime)}}</div>
      </div>
      <div class="com-like" v-if="itemData.from==='detail'">
        <div class="comment">
          <span class="icon icon-comment"></span> <span  class="info-content">{{itemData.topics.commentNumber}}</span>
        </div>
        <div class="like" @click="likeEvent(itemData.topics.topicID,-1)">
          <span class="icon icon-like" :class="{active: itemData.isLike}"></span> <span class="info-content">{{itemData.topics.likeNumber}}</span>
        </div>
      </div>
    </section>
    <section class="content">{{itemData.topics.content}}</section>
    <section class="images"  :class="'type_'+itemData.topics.attachmentsList.length" v-if="itemData.topics.attachmentsList.length">
      <div v-for="(item,index) in itemData.topics.attachmentsList" :key="index" class="image-box" :class="'img_'+index" :style="{backgroundImage: `url(${item.fileUrl})`}">
        <!-- <img :src="item.fileUrl" alt=""> -->
      </div>
    </section>
  </div>
</template>

<script>
import { timestampFormat } from '../../../libs/utils'
import { API_ADD_THUMBS_UP } from '@/service/social'
import { certificateMixin } from '@/components/mixins'
export default {
  mixins: [ certificateMixin ],
  props: {
    itemData: Object
  },
  data () {
    return {
    }
  },
  mounted () {
    // console.log(this.itemData)
  },
  methods: {
    formTime (time) {
      return timestampFormat(time)
    },
    likeEvent (contentID) {
      this.certificateCheck().then(() => {
        let reqData = {
          userId: this.$store.getters.getUserInfo.userId,
          contentId: contentID,
          type: 1
        }
        API_ADD_THUMBS_UP(reqData).then(resData => {
          this.itemData.isLike = true
          this.itemData.topics.likeNumber++
        })
      })
    }
  }
}
</script>

<style scoped lang="less">
.social-item {
  .item-head {
    display: flex;
    align-items: center;
    .avatar {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      overflow:  hidden;
      margin-right: 15px;
      img {
        display: block;
        width: 100%;
        height: 100%;
      }
    }
    .info {
      flex: 1;
      height: 40px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
    }
    .name {
      font-size: 15px;
      font-weight: bold;
    }
    .time {
      font-size: 12px;
      color: #3B3B3B;
    }
  }
  .content {
    font-size: 14px;
    line-height: 23px;
    margin-top: 15/2px;
  }
  .image-box{
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center center;
  }
  .type_1{
    width: 75%;
    .image-box {
      padding-top: 90%;
      background-size: contain;
    }
  }
  .type_2>div,.type_4>div{
    width: 50%;
    height: 321/2px;
    padding-right: 3.5/2px;
    box-sizing: border-box;
    float: left;
  }
  .type_3 {
    .img_0{
    width: 50%;
    height: 321/2px;
    padding-right: 3.5/2px;
    box-sizing: border-box;
    float: left;
   }
    .img_1,.img_2{
      width: 50%;
      height: 156/2px;
      padding-left: 3.5/2px;
      box-sizing: border-box;
      margin-bottom: 4px;
      float: left;
      &:last-child {
        margin-bottom: 0;
      }
    }
  }

  .type_5{
    .img_0,.img_3,.img_4{
      width: 50%;
      height: 321/2px;
      padding-right: 3.5/2px;
      box-sizing: border-box;
      float: left;
    }
    .img_1,.img_2{
      width: 50%;
      height: 156/2px;
      padding-left: 3.5/2px;
      box-sizing: border-box;
      margin-bottom: 4px;
      float: left;
      &:last-child {
        margin-bottom: 0;
      }
    }
  }

  .type_6{
    .img_0,.img_3{
      width: 50%;
      height: 321/2px;
      padding-right: 3.5/2px;
      box-sizing: border-box;
      float: left;
    }
    .img_1,.img_2,.img_4,.img_5{
      width: 50%;
      height: 156/2px;
      padding-left: 3.5/2px;
      box-sizing: border-box;
      margin-bottom: 4px;
      float: left;
      &:last-child {
        margin-bottom: 0;
      }
    }
  }

  .images {
    margin: 10px auto;
    overflow: hidden;
    .big {
      width: 50%;
      height: 321/2px;
      padding-right: 3.5/2px;
      box-sizing: border-box;
      float: left;
    }
    .small {
      width: 50%;
      height: 156/2px;
      padding-left: 3.5/2px;
      box-sizing: border-box;
      margin-bottom: 4px;
      float: left;
      &:last-child {
       margin-bottom: 0;
      }
    }
    img {
      display: block;
      width: 100%;
      height: 100%;
    }
  }
  .com-like {
    display: flex;
  }
  .comment {
    margin-right: 10px;
  }

  .comment,.like{
    display: flex;
    .icon {
      margin-right: 2px;
    }
  }
}

</style>
